﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NUnit.Framework;

namespace Boggle.Dictionaries.Tests
{
	/// <summary>
	/// Tests the SlowOptimisticDictionary.
	/// </summary>
	public class TestSlowOptimisticDictionary
	{
		/// <summary>
		/// Tests the dictionary's constructor.
		/// </summary>
		[Test]
		public void TestCtorNoParams()
		{
			var dict = new SlowOptimisticDictionary();
			Assert.IsFalse(dict.IsDefineSupported);
			Assert.IsNotNullOrEmpty(dict.Name);
			Assert.IsNotNullOrEmpty(dict.Description);
		}

		#region CtorWithParam

		/// <summary>
		/// Tests the CtorWithParam method.
		/// </summary>
		[Test, TestCaseSource("GetCtorWithParamCases")]
		public void TestCtorWithParam(Int32 delayMs)
		{
			var dict = new SlowOptimisticDictionary(delayMs);
			Assert.IsFalse(dict.IsDefineSupported);
			Assert.IsNotNullOrEmpty(dict.Name);
			Assert.IsNotNullOrEmpty(dict.Description);
		}

		/// <summary>
		/// Provides test cases for the CtorWithParam test.
		/// </summary>
		/// <returns>Test cases for the CtorWithParam test method.</returns>
		public IEnumerable<ITestCaseData> GetCtorWithParamCases()
		{
			yield return new TestCaseData(Int32.MinValue).Throws(typeof(ArgumentOutOfRangeException));
			yield return new TestCaseData(-1).Throws(typeof(ArgumentOutOfRangeException));
			yield return new TestCaseData(0);
			yield return new TestCaseData(Int32.MaxValue);
		}

		#endregion

		#region IsWord Tests

		/// <summary>
		/// Tests the dictionary's IsWord method.
		/// </summary>
		/// <param name="word"></param>
		/// <returns></returns>
		[Test, TestCaseSource("GetIsWordCases")]
		public Boolean TestIsWord(String word)
		{
			var dict = new SlowOptimisticDictionary(0);
			return dict.IsWord(word);
		}

		/// <summary>
		/// Provides test cases for the IsWord method.
		/// </summary>
		/// <returns></returns>
		private IEnumerable<ITestCaseData> GetIsWordCases()
		{
			yield return new TestCaseData(null).Returns(true);
			yield return new TestCaseData(String.Empty).Returns(true);
			yield return new TestCaseData("a").Returns(true);
			yield return new TestCaseData("hello").Returns(true);
			yield return new TestCaseData("qwertyuiop").Returns(true);
		}

		#endregion

		/// <summary>
		/// Tests that this dictionary's DefineWord method throws
		/// an appropriate exception.
		/// </summary>
		[Test, ExpectedException(typeof(NotImplementedException))]
		public void TestDefine()
		{
			var dict = new SlowOptimisticDictionary();
			dict.Define("fish");
		}
	}
}
